<?php

namespace App\Http\Controllers\Api;

use App\Models\Bar;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use App\Http\Resources\Bar as BarCollection;

class BarsController extends ApiController
{

    /**
     *
     *
     *
     * @api {get} /bars/hot_bar 热门吧
     * @apiName bar hot_bar
     * @apiGroup Bar
     *
     * @apiParam {String} [type] 1 => 关注数 2=> 帖子数
     * @apiParam {String} [page] 页数
     * @apiParam {String} [limit] 限制的条数
     *
     * @apiVersion 2.0.0
     *
     * @apiSampleRequest /api/bars/hot_bar
     *
     *
     *
     */
    public function hotBar(){

        $type = Input::get('type') ?: 1;
        $limit = Input::get('limit') ?: 20;


        // 人数最多的吧
        if ($type == 2){

            $bars = Bar::withCount('posts as posts_count')
                ->orderBy('posts_count','desc')
                ->paginate($limit);
        }else{

            $bars = Bar::withCount('fans as fans_count')
                ->orderBy('fans_count','desc')
                ->paginate($limit);
        }


        return BarCollection::collection( $bars);


    }

}
